#ifndef MEDIA_STREAMERDOWNLOADONLINEFILE_H
#define MEDIA_STREAMERDOWNLOADONLINEFILE_H
#include <memory>
#include <mutex>
#include <vector>
#include <string>
#include <functional>
#include <atomic>
#include <thread>
#include <map>


typedef enum
{
    STREAMER = 0,
    BGM
}FileDownloadType;

namespace Media{

    class StreamerDownloadOnlineFile{
    public:
        using Ptr = std::shared_ptr<StreamerDownloadOnlineFile>;
        using downloadCb = std::function<void(bool, std::string, std::string)>;
        // friend Ptr std::make_shared<Media::StreamerDownloadOnlineFile>();  // 声明为友元
        static Ptr instance(FileDownloadType type){
            if(sm_instance.find(type) == sm_instance.end()){
                std::lock_guard<std::mutex> lock(sm_instanceLock);
                sm_instance[type] = std::make_shared<StreamerDownloadOnlineFile>();
            }
            return sm_instance.find(type)->second;
        }

        ~StreamerDownloadOnlineFile();
        StreamerDownloadOnlineFile(){}

        bool start(std::vector<std::string> urls, downloadCb cb, std::string path);
        
        bool stop();

        
    private:
       
        bool downloadUrls();
    private:
        static std::map<FileDownloadType, Media::StreamerDownloadOnlineFile::Ptr> sm_instance;
        static std::mutex sm_instanceLock; 
        
        std::vector<std::string> m_urls;
        std::string m_savePath;
        downloadCb m_downloadCallback;
        std::atomic<bool> m_stopLoad{true};
        std::atomic<bool> m_downloadRunning{false};
    };

}

#endif